<template>
        <tm-overlay v-model:show="props.friendPoverlay" contentAnimation style="border-radius: 20rpx;" @close="close">
            <view @click.stop="">
                <tm-sheet :width="540" style="border-radius: 20rpx;padding: 0;" parenClass="sheet">
                    <view>
                        <view class="top">
                            好友申请
                        </view>
                        <view class="mes">
                            <text class="mes-name">{{ props.data.nick }}</text>申请加你为好友
                        </view>
                        <view class="laiyuan" v-if="formatSource(props.data.source)">
                            <text class="from">来自</text>{{formatSource(props.data.source)}}
                        </view>
                        <view class="info">
                            <text>
                                {{props.data.wording}}
                            </text>
                        </view>
                    </view>
                    <view style="height: 220rpx;margin-top:30rpx;">
                        <view class="btn">
                            <view class="tongyi" @click="accept">同意</view>
                            <view class="jujue" @click="refuse">拒绝</view>
                        </view>
                    </view>
                    <!-- <view class=" types">
                        <view class="tongyi">
                            已同意
                        </view>
                        <view class="jujue">已拒绝</view>
                    </view> -->
                </tm-sheet>
            </view>
        </tm-overlay>
</template>
<script lang="ts" setup>
import { ref, getCurrentInstance, defineProps, defineEmits } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
import { acceptAddFriend,refuseAddFriend,deleteAddFriend} from '@/hooks/imHooks'
const showWin = ref(true)
const pos = ref('bottom');
const props: any = defineProps({
    friendPoverlay: Boolean,
    data: Object
});
const emit = defineEmits(['closefriendProps','showMsg']);
// 同意好友申请
// 拒绝好友申请
const accept = async () => {

    const res= await acceptAddFriend({userId:props.data.userID,remark:''})
    if(res==='success'){
        emit('closefriendProps', false);
        emit('showMsg',{
            duration: "2000",
            showIcon: false,
            mask: false,
            dark: true,
            text: `${props.data.nick} 成为了你的好友`,
        });
    }

    emit('closefriendProps', false);
}

const formatSource = (source)=>{
    if(source==="AddSource_Type_discover"){
        return '发现-个人主页'
    }
    if(source==="AddSource_Type_search"){
        return 'ID查找'
    }
    if(source==="AddSource_Type_chat"){
        return '会话'
    }
    if(source==="AddSource_Type_quanzhu"){
        return '联系群主'
    }
    return ''
}

const refuse = async () => {

    const res= await refuseAddFriend(props.data.userID)
    if(res==='success'){
        emit('closefriendProps', false);
        emit('msg',{
            duration: "2000",
            showIcon: false,
            mask: false,
            dark: true,
            text: `已拒绝 ${props.data.nick} 的好友申请`,
        });
    }

}
// 点击遮罩关闭
const close = () => {
    emit('closefriendProps', false);

}
</script>
<style lang="scss" scoped>
.sheet {
    overflow: hidden;

    .top {
        width: 100%;
        height: 124rpx;
        background: linear-gradient(0, #FFFFFF 0%, #BAF3DA 100%, #CBF7E4 100%);
        font-size: 32rpx;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 600;
        color: #333333;
        text-align: center;
        padding-top: 29rpx;
    }

    .mes {
        font-size: 30rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
        text-align: center;

        .mes-name {
            font-size: 30rpx;
            color: #333333;
            margin-right: 10rpx;
        }
    }

    .laiyuan {
        font-size: 24rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #666666;
        text-align: center;
        margin: 22rpx 0 0 0;

        .from {
            font-size: 24rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #999999;
            margin-right: 16rpx;
        }

    }

    .info {
        width: 420rpx;
        background: #F5F5F5;
        border-radius: 10rpx;
        margin: 20rpx auto;
        display: flex;

        flex-wrap: wrap;
        box-sizing: border-box;
        padding:20rpx;
        min-height:200rpx;

        text {
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            font-size: 28rpx;
        }
    }

    .btn {
        width: 460rpx;
        margin: 0 auto;

        .tongyi {
            width: 100%;
            height: 80rpx;
            background: linear-gradient(120deg, #29DBA3 0%, #64F1C5 100%);
            border-radius: 20rpx;
            font-size: 32rpx;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 600;
            color: #FFFFFF;
            text-align: center;
            line-height: 80rpx;
        }

        .jujue {
            margin-top: 20rpx;
            width: 100%;
            height: 80rpx;
            border-radius: 20rpx;
            border: 2rpx solid #CCCCCC;
            font-size: 32rpx;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 600;
            color: #999999;
            text-align: center;
            line-height: 80rpx;
        }
    }

    .types {
        width: 100%;
        height: 120rpx;

        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;

        .tongyi {
            font-size: 32rpx;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #1DC691;
        }

        .jujue {
            font-size: 32rpx;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #999999;
        }
    }
}
</style>